package com.syq.dao.impl;

import com.syq.dao.CoachGoodAtCoursetypeDao;
import com.syq.entity.CoachGoodAtCoursetype;
import com.syq.mapper.CoachGoodAtCoursetypeMapper;
import com.syq.page.PageInfo;
import com.syq.utils.GenNumTools;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("coachGoodAtCoursetypeDao")//一般实现类不会直接生成默认对象名 而是使用 接口的默认对象名
public class CoachGoodAtCoursetypeDaoImpl implements CoachGoodAtCoursetypeDao {
    @Resource //autowired 会装配能够直接扫描到的对象  resource spring容器运行的时候才找到需要的对象  注入
    private CoachGoodAtCoursetypeMapper coachGoodAtCoursetypeMapper;
    public List<CoachGoodAtCoursetype>  getAllCoachGoodAtCoursetypes() throws Exception{
        return coachGoodAtCoursetypeMapper.selectByExample(null);
    }

    @Override
    public Integer deleteCoachGoodAtCoursetypeByCCtno(String cCtno)  throws Exception{
        return coachGoodAtCoursetypeMapper.deleteByPrimaryKey(cCtno);
    }

    @Override
    public Integer updateCoachGoodAtCoursetypeByCCtno(CoachGoodAtCoursetype coachGoodAtCoursetype)  throws Exception{
        return coachGoodAtCoursetypeMapper.updateByPrimaryKey(coachGoodAtCoursetype);
    }

    @Override
    public Integer addCoachGoodAtCoursetype(CoachGoodAtCoursetype coachGoodAtCoursetype)  throws Exception{
        coachGoodAtCoursetype.setcCtno(initId());
        return coachGoodAtCoursetypeMapper.insertSelective(coachGoodAtCoursetype);
    }
    public String initId(){
        String maxCCtno = coachGoodAtCoursetypeMapper.getMaxCCtno();
        return GenNumTools.initId("cct",4,maxCCtno);
    }

    @Override
    public List<CoachGoodAtCoursetype> getCoachGoodAtCoursetypeByPage(PageInfo pageInfo )  throws Exception{
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("currPage",pageInfo.getCurrPage());
        map.put("pageSize",pageInfo.getPageSize());
        int itemCount = (int)coachGoodAtCoursetypeMapper.countByExample(null);
        pageInfo.setItemCount(itemCount);
        return coachGoodAtCoursetypeMapper.getCoachGoodAtCoursetypeByPage(map);
    }

    @Override
    public Integer updateCoachGoodAtCoursetypes(CoachGoodAtCoursetype coachGoodAtCoursetype) {
        return null;
    }
//
//    @Override
//    public CoachGoodAtCoursetype selectCoachGoodAtCoursetypeWithChildren(String cCtno){
//        return coachGoodAtCoursetypeMapper.selectCoachGoodAtCoursetypeWithChildren(cCtno);
//    }
//
//    @Override
//    public CoachGoodAtCoursetype getCoachGoodAtCoursetypeWithOrdrees(String cCtno) throws Exception {
//        return coachGoodAtCoursetypeMapper.getCoachGoodAtCoursetypeWithOrdrees(cCtno);
//    }
//
//    @Override
//    public CoachGoodAtCoursetype getAccountByAccountName(String cname) {
//            return coachGoodAtCoursetypeMapper.getAccountByAccountName(cname);
//    }
//
//    /**
//     *
//     * @param cname
//     * @return
//     */
//    public List<CoachGoodAtCoursetype> getCoachGoodAtCoursetypeByExample(String cname) {
//        CoachGoodAtCoursetypeExample coachGoodAtCoursetypeExample =new CoachGoodAtCoursetypeExample();
//        coachGoodAtCoursetypeExample.createCriteria().andCnameEqualTo(cname);
//        return coachGoodAtCoursetypeMapper.selectByExample(coachGoodAtCoursetypeExample);
//    }
//
//    @Override
//    public Integer updateCoachGoodAtCoursetype(CoachGoodAtCoursetype coachGoodAtCoursetype) { return coachGoodAtCoursetypeMapper.updateByPrimaryKey(coachGoodAtCoursetype); }

//    public Integer updateByPrimaryKeySelective(CoachGoodAtCoursetype coachGoodAtCoursetype) { return coachGoodAtCoursetypeMapper.updateByPrimaryKeySelective(coachGoodAtCoursetype); }
//
//
//    @Override
//    public Integer updateCoachGoodAtCoursetypes(CoachGoodAtCoursetype coachGoodAtCoursetype) { return coachGoodAtCoursetypeMapper.updateByPrimaryKeys(coachGoodAtCoursetype); }

}
